<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    //定义一个空的学生对象
    function Student() {}
    //实例化学生对象
    let s1 = new Student();
    //动态给对象添加属性和方法
    s1.name = "张三";
    s1.age = 18;
    s1.run = function () {
        alert(this.name+":"+this.age);
    }
    //调用方法
    s1.run();

        //直接实例化对象
    let p1 = {};
    p1.name = "李四";
    p1.age = 18;
    p1.run = function () {
        alert(this.name+":"+this.age);
    }
    //调用对象的方法
    p1.run();

    //实例化带属性和方法的对象
    let p2 = {
        name:"蔣晴晴",
        age:20,
        run:function () {
            alert(this.name+":"+this.age);
        }
    }
    //调用方法
    p2.run();
    //通过数组对象的方式 封装几个商品的数据
    let arr = [{title:"小米手机",price:3000,num:1000},
        {title:"华为手机",price: 5000,num: 200},
        {title: "iphone",price: 6000,num: 500}];
</script>
</body>
</html>